package com.vaadin.tutorial.crm.backend.entity;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description:
 * @Author: Fan
 * @Date: 2021/1/16 20:25
 * @Version 1.0
 */
@Entity
@Table(name = "stu_student")
public class Student implements Cloneable{

    public enum StuGender{
        WOMAN(0,"test1"), MAN(1,"test2");

        private Integer index;
        private String value;

         StuGender(Integer index , String  value ) {
            this.value = value;
            this.index = index;
        }

        public static String[] valueList(){
            StuGender[] stuGender = StuGender.values();
            List<String> genderList = new ArrayList<>(16);
            for(StuGender gender : stuGender){
                genderList.add(gender.getValue());
            }
            if (genderList != null){
                return genderList.toArray(new String[genderList.size()]);
            }else{
                return null;
            }
        }
        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public Integer getIndex() {
            return index;
        }

        public void setIndex(Integer index) {
            this.index = index;
        }
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer stuId;

    @NotNull
    @NotEmpty
    private String stuNum;

    @NotNull
    @NotEmpty
    private String stuName;

    @Enumerated(EnumType.ORDINAL)
    @NotNull
    private Student.StuGender stuGender;
    /*@Temporal(TemporalType.DATE)//生成yyyy-MM-dd类型的日期
    //出参时间格式化
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    //入参时，请求报文只需要传入yyyymmddhhmmss字符串进来，则自动转换为Date类型数据
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")*/
    private LocalDate stuBirth;

    @NotNull
    @NotEmpty
    private String stuPhone;

    @NotNull
    @NotEmpty
    private String phoneFamily;

    @NotNull
    @NotEmpty
    private String stuMonitor;

    private String stuCollege;

    private byte[] stuPhoto;

    public Integer getStuId() {
        return stuId;
    }

    public void setStuId(Integer stuId) {
        this.stuId = stuId;
    }

    public String getStuNum() {
        return stuNum;
    }

    public void setStuNum(String stuNum) {
        this.stuNum = stuNum;
    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public StuGender getStuGender() {
        return stuGender;
    }

    public void setStuGender(StuGender stuGender) {
        this.stuGender = stuGender;
    }

    public LocalDate getStuBirth() {
        return stuBirth;
    }

    public void setStuBirth(LocalDate stuBirth) {
        this.stuBirth = stuBirth;
    }

    public String getStuPhone() {
        return stuPhone;
    }

    public void setStuPhone(String stuPhone) {
        this.stuPhone = stuPhone;
    }

    public String getPhoneFamily() {
        return phoneFamily;
    }

    public void setPhoneFamily(String phoneFamily) {
        this.phoneFamily = phoneFamily;
    }

    public String getStuMonitor() {
        return stuMonitor;
    }

    public void setStuMonitor(String stuMonitor) {
        this.stuMonitor = stuMonitor;
    }

    public String getStuCollege() {
        return stuCollege;
    }

    public void setStuCollege(String stuCollege) {
        this.stuCollege = stuCollege;
    }

    public byte[] getStuPhoto() {
        return stuPhoto;
    }

    public void setStuPhoto(byte[] stuPhoto) {
        this.stuPhoto = stuPhoto;
    }

    @Override
    public String toString() {
        return "Student{" +
                "stuId=" + stuId +
                ", stuNum='" + stuNum + '\'' +
                ", stuName='" + stuName + '\'' +
                ", stuGender=" + stuGender +
                ", stuBirth=" + stuBirth +
                ", stuPhone='" + stuPhone + '\'' +
                ", phoneFamily='" + phoneFamily + '\'' +
                ", stuMonitor='" + stuMonitor + '\'' +
                ", stuCollege='" + stuCollege + '\'' +
                ", stuPhoto=" + Arrays.toString(stuPhoto) +
                '}';
    }
}
